<?php
namespace App\Query;

use App\Model\User;
use App\Query\Traits\UserTrait;

class UserQuery extends \HyperfStore\Query
{
    use UserTrait;
    
    // 构建模型
    protected static function build()
    {
        return User::latest();
    }

    // 渴望加载
    protected static function with()
    {
        return ['level', 'shopMy', 'user', 'shop'];
    }
    
    // 按需加载
    public static function load($model)
    {
        return $model->load(static::with());
    }
    
    // 时间区间
    protected static function queryTime($model, $where)
    {
        return $model->whereBetween('created_at', $where);
    }
    
    // 不需要复投的用户
    public static function moneyPayNo($model = null)
    {
        return UserQuery::model($model)->where('money_pay', 0);
    }
    
    // 获取满足最小区的用户
    public static function moneyUserMin($money)
    {
        return static::model()->whereDoesntHave('userChild', function ($query) use($money){
            $query->where('money_user', '<=', $money);
        })->where('money_user', '>=', $money);
    }
}